import toolService from '../prototypes/tool.js';
/**
 * 日期格式化
 * 
 * @param timestamp 时间戳 
 * @param format 格式
 * @param join 连接符
 */
export default function (timestamp, format = 'second', join = '-') {
    const myDate = new Date(timestamp);
    const year = myDate.getFullYear();
    const month = myDate.getMonth() + 1;
    const day = myDate.getDate();
    const hours = toolService.formatNumber(myDate.getHours());
    const minutes = toolService.formatNumber(myDate.getMinutes());
    const seconds = toolService.formatNumber(myDate.getSeconds());
    if (format == 'second' || format == '') {
        return `${year}${join}${month}${join}${day} ${hours}:${minutes}:${seconds}`;
    } else if (format == 'minute') {
        return `${year}${join}${month}${join}${day} ${hours}:${minutes}`;
    } else if (format == 'day') {
        return `${year}${join}${month}${join}${day}`;
    } else if (format == 'date') {
        return `${year}${join}${month}${join}${day}`;
    } else if (format == 'time') {
        return `${hours}:${minutes}:${seconds}`;
    } else {
        return '过滤器格式错误';
    }
}
